<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.xml.crypto.Data" %>
<%@ page import="java.text.SimpleDateFormat" %><%--
  Created by IntelliJ IDEA.
  User: 肖林
  Date: 2018/6/11
  Time: 11:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>超级课程表</title>
    <style type="text/css">
        table {
            border: 1px solid #000;
            border-collapse: collapse;

        }

        td, tr {
            border: 1px solid #000;
            padding: 10px;
            width: 100px;
            height: 50px;
            text-align: center;
        }
    </style>
</head>
<body>
<table>
    <thead>
    <tr>
        <td>id</td>
        <td>时间</td>
        <td>课程</td>
        <td>教室</td>
    </tr>
    </thead>
    <tbody>
    <%
        class user {
            int id;
            Time time;
            String course;
            String classroom;

            public user(int id, Time time, String course, String classroom) {
                this.id = id;
                this.time = time;
                this.course = course;
                this.classroom = classroom;
            }
        }

        List<user> list = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        String sql = "select * from 16xinben01";
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/timetable?serverTimezone=Asia/Shanghai",
                "root"  ,
                "195122"
        );
        statement = connection.createStatement();

        resultSet = statement.executeQuery(sql);

        while (resultSet.next()) {
            int id = resultSet.getInt(1);
            Time time = resultSet.getTime(2);
            String course = resultSet.getString(3);
            String classroom = resultSet.getString(4);

            user user = new user(id, time, course, classroom);
            list.add(user);
        }

        resultSet.close();
        statement.close();
        connection.close();
        pageContext.setAttribute("user",user);

//          for (user user : list) {
//              out.write("<tr> <td>" + user.id + "</td><td>" + user.time + "</td> <td>" + user.course
//                      + "</td> <td>" + user.classroom + "</td> </tr>");
//          }
    %>
    <c:set var="nowDate" value="<%=System.currentTimeMillis()%>"></c:set>
    <c:choose>
        <c:when test="${nowDate==user[1].time}">
            <c:out value="${user[1].course},${user[1].classroom}"></c:out>
        </c:when>
    </c:choose>
    </tbody>
</table>
</body>
</html>
